const userName = 'userName'
const mineId = 'mineId'
const token = 'token'
const code = 'code'
import { get, post } from '../request/index'

// 检测登录状态，返回 true / false
async function isLoged() {
  const token = getToken()
  if (!token) {
    return false
  }else{
    return true
  }
  
}


function getMineId() {
  let prolist = JSON.parse(wx.getStorageSync('prolist'))
  return prolist.mineId
}
function getuserid(){
  let prolist = JSON.parse(wx.getStorageSync('prolist'))
    
  return prolist
}

function getUserName() {
  return wx.getStorageSync(userName)
}

function getToken() {
  return wx.getStorageSync(token)
}


function toLogin() {
  wx.redirectTo({
    url: '/pages/login/login',
  })
}



async function logout() {
  wx.removeStorageSync(userName)
  wx.removeStorageSync(mineId)
  wx.removeStorageSync(token)

  wx.showToast({
    title: '登出成功'
  })
  
  setTimeout(function(){
    wx.redirectTo({
      url: '/pages/login/login',
    })
  },1000)

  
}

function saveUser(a, b, c) {
  wx.setStorageSync(userName, a)
  wx.setStorageSync(mineId, b)
  wx.setStorageSync(token, c)
}

module.exports = {
  isLoged: isLoged,
  toLogin: toLogin,
 
  logout: logout,
  saveUser: saveUser,
  
  getMineId: getMineId,
  getUserName: getUserName,
  getToken: getToken,
  getuserid
}